/**
 * @file   test_mutex003.c
 * @brief	Test two BRR tasks without mutex to contrast with test004.c.
 * Expected result: 0 because without using mutex
 */
#include "../header/common.h"
#include "../header/os.h"
#include "../header/uart.h"
#include "../header/trace.h"
#include <util/delay.h>
#ifdef test_mutex003

enum { A=1, B};
const unsigned char PPP[] = {};
const unsigned int PT = 0;
EVENT* print_event;
extern uint16_t trace_counter;
int count = 0;
int flag = 0;

void generic_task(void)
{
	int temp;
	int arg = 0;
	int tracker = 0;
	arg = Task_GetArg();

    for(;;)
    {
    	if (tracker == 500) {
    		PORTD |= _BV(PORTD7);
    		if (flag == 1) {
    			Event_Signal(print_event);
    		}
    		else {
    			PORTD |= _BV(PORTD5);
    			flag++;
    			Task_Terminate();
    		}
    	}
    	temp = count + 1;
    	Task_Next();
    	count = temp;
    	tracker++;
    	Task_Next();
    }
}

int main(void) {
	//use pins 4,5,6 and 7 on Port D for output
	DDRD = (1<<PORTD4) | (1<<PORTD5) | (1<<PORTD6) | (1<<PORTD7);
	UART_BPS bitrate = UART_38400;
	uart_init(bitrate);

    print_event = Event_Init();

    Task_Create(generic_task, 0, BRR, 1);
    Task_Create(generic_task, 0, BRR, 1);


    Event_Wait(print_event);
    print_result(500);
    return 0;
}

#endif
